//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by HanXujie on 2017/4/10.
//  Copyright © 2017年 thinker. All rights reserved.
//

import UIKit


extension UIBarButtonItem{
    
    
    /*
     便利构造函数，主要是简化创建控件
     */
    
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认是16号
    ///   - target: target description
    ///   - action: action description
    ///   - isBackButton: 是否是返回按钮，如果是加上箭头
    convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector,isBackButton:Bool = false) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBackButton {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
            
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView:btn)
    }
}
